const app = require("express")();
const bodyParser = require("body-parser");
const { nanoid } = require("nanoid");
const Mock = require("mockjs");

// 配置 bodyParser 获取post请求提交的数据
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());

app.get("/search/users", (req, res) => {
  const data = Mock.mock({
    code: "00",
    message: "查询功能",
    "data|10": [
      {
        id: Mock.Random.guid(),
        "name|1": "@cname",
        age: "@integer(30, 50)",
        createDate: "@date(yyyy-MM-dd)",
        photo: Mock.Random.image('200x200', '#50B347', '#FFF', 'Mock.js'),
      },
    ],
  });
  res.send(data);
});

app.listen(5002, () => {
  console.log("服务已启动，地址：http://localhost:5002");
});
